package com.desaysv.wandroid.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.desaysv.svview.adapter.BaseRecycleAdapter;
import com.desaysv.wandroid.R;
import com.desaysv.wandroid.entity.AirticEntity;
import com.desaysv.wandroid.utils.WAConstant;

import org.joda.time.DateTime;

import java.util.List;

/**
 * @author linzi
 * @date 2022-11-16
 */
public class AirticAdapter extends BaseRecycleAdapter {
    private List<AirticEntity.DatasBean>mDatas;
    private Context context;
    private int mTopAirticCount=-1;

    public AirticAdapter(List<AirticEntity.DatasBean> mDatas, Context context) {
        this.mDatas = mDatas;
        this.context = context;
    }

    public void setTopAirticCount(int mTopAirticCount) {
        this.mTopAirticCount = mTopAirticCount;
    }

    @Override
    public Context setContext() {
        return context;
    }

    @Override
    public int setView() {
        return R.layout.item_layout_airtic;
    }

    @Override
    public int setSize() {
        return mDatas==null?0:mDatas.size();
    }

    @Override
    public void bind(HolderProxy item, int position) {
        if(position<mTopAirticCount){
            item.setVisible(R.id.tvTopTag,View.VISIBLE);
        }else{
            item.setVisible(R.id.tvTopTag,View.GONE);
        }
        AirticEntity.DatasBean data=mDatas.get(position);
        item.setText(R.id.tvTitle,data.getTitle());
        item.setText(R.id.tvShareTag, TextUtils.isEmpty(data.getAuthor())?data.getShareUser():data.getAuthor());
        item.setText(R.id.tvTypeTag, data.getSuperChapterName());
        item.setText(R.id.tvTypeTag2,data.getChapterName());
        item.setText(R.id.tvPublishTime, new DateTime(data.getPublishTime()).toString(WAConstant.dft));
        item.setText(R.id.tvPublishUser,TextUtils.isEmpty(data.getAuthor())?"分享者："+data.getShareUser():"作者："+data.getAuthor());

    }
}
